#import "CoinGameViewController.h"
#import <Foundation/NSString.h>
#import <Foundation/Foundation.h>

#import "MainMenuController.h"
#import "CoinGame.h";
@implementation CoinGameViewController
//test
//@synthesize mainMenuController;
@synthesize coinGame;
@synthesize mode;
@synthesize d;
@synthesize i;
@synthesize increase;
@synthesize menuView;
@synthesize gameSelectView;
@synthesize difficultySwitch;
@synthesize about;
@synthesize increaseSwitch;


-(IBAction)checkAbout:(id)sender;
{
	[self.view addSubview:about];
	[self.view bringSubviewToFront:about];
	about.hidden = FALSE;
}

- (IBAction)returnfromAbout:(id)sender;
{
	about.hidden=TRUE;	
}


-(IBAction)setOptions:(id)sender;
{
	[self.view addSubview:menuView];
	[self.view bringSubviewToFront:menuView];
	menuView.hidden = FALSE;
}

- (IBAction)closeOptions:(id)sender{
	menuView.hidden=TRUE;
}

-(IBAction)pickGame:(id)sender;
{
	[self.view addSubview:gameSelectView];
	[self.view bringSubviewToFront:gameSelectView];
	gameSelectView.hidden = FALSE;
}

- (IBAction)closePickGame:(id)sender{
	gameSelectView.hidden=TRUE;
}

-(IBAction)startGame:(id)sender;
{
	
	CoinGame *X = [[CoinGame alloc] initWithNibName:@"CoinGame" bundle:nil];
	self.coinGame = X;
	[X release];
	[self presentModalViewController:coinGame animated:YES];
	
	NSString *button = [sender titleForState:UIControlStateNormal];
	
	//the following code is used to set the game modes
	if ([button isEqualToString:@"60 Second Race"])
	{ 
		mode=1; //mode one is answer as much question as you can in 60 second
	}
	else if([button isEqualToString:@"10 Question Race"])
	{
		mode=2; //mode 2 is answer 10 question as fast as you can
	}
	else if([button isEqualToString:@"Sudden Death"])
	{
		mode=3; //mode 3 is answer question until you get one wrong or out of time
	}
	else if([button isEqualToString:@"Survival"])
	{
		mode=4;	//mode 4 you start off with 3 lives, every 5 question you get right you gain one
	}			//and every time you get a question wrong you lose one
	else if([button isEqualToString:@"60 Second Cashier"])
	{
		mode=5;	 //mode 5 is still a work in progress, you need to minus the 2 values and make the total with the coins
	}
	
	[coinGame setMode: (mode+d*10+increase*1000)];
	
}


- (IBAction)backOne:(id)sender
{
	
	[[self parentViewController] dismissModalViewControllerAnimated:YES]; 
	[self dismissModalViewControllerAnimated:YES];
}


- (IBAction)setDifficulty:(id)sender
{
	d=difficultySwitch.selectedSegmentIndex;
	
}

- (IBAction)increaseToggle:(id)sender{
	
	
	increase=increaseSwitch.selectedSegmentIndex;
}


/*
 - (IBAction)openMainMenu:(id)sender
 {
 [UIView beginAnimations:@"View Flip" context:nil];
 [UIView setAnimationDuration:1.25];
 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
 if (self.mainMenuController == nil)
 {
 MainMenuController *mainController = 
 [[MainMenuController alloc] initWithNibName:@"MainMenu" bundle:nil];
 self.mainMenuController = mainController;
 [mainController release];
 }
 [UIView setAnimationTransition:
 UIViewAnimationTransitionFlipFromLeft
 forView:self.view cache:YES];
 
 
 [mainMenuController viewWillDisappear:YES];
 
 [self.view insertSubview:mainMenuController.view atIndex:0];
 [mainMenuController viewDidDisappear:YES];
 
 [UIView commitAnimations];
 
 }
 */


//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//	// Return YES for supported orientations
//	return (interfaceOrientation == UIInterfaceOrientationPortrait);
//}



- (void)dealloc {
	
	//	[mainMenuController release];
	[menuView release];
	[gameSelectView release];
	[coinGame release];
	[super dealloc];
}


- (void)didReceiveMemoryWarning {
	[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
	// Release anything that's not essential, such as cached data
}


@end
